<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>app用户管理2.0</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="../../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../../css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="../../css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="../../css/animate.css" rel="stylesheet">
    <link href="../../css/plugins/ztree/style.css?v=4.1.0" rel="stylesheet">

</head>
<style type="text/css">
    .setOs{
        width: 20%;
        height: 26px;
    }
    div[class="bars pull-left"]{
        width: 90%;
    }
</style>
<body class="">
<div class="wrapper wrapper-content animated fadeInRight">
	
    <div id="toolbar" class="form-inline">
        <div class="">
            <div class="form-group">
                <input type="text" class="form-control" data-bind="value:mobile" placeholder="手机号">
            </div>
            <div class="form-group">
                <input type="text" class="form-control" data-bind="value:name"  placeholder="姓名">
            </div>
            <div class="form-group">
                <input type="text" class="form-control" data-bind="value:numId"  placeholder="用户id">
            </div>
            <div class="form-group">
                <label for="userType">用户类型</label>
                <select data-bind="value:userType" id="userType" class="form-control">
                	<option value="" style="color:green;">请选择</option>
                   	<option value="1" style="color:green;">基层医生</option>
                   	<option value="2" style="color:green;">医生经纪人</option>
                  	<option value="3" style="color:green;">讲师专家</option>
                </select>
            </div>
            <div class="form-group">
                <label for="checkFlag">审核状态</label>
                <select data-bind="value:checkFlag" id="checkFlag" class="form-control">
                    <option value="" style="color:green;">请选择</option>
                    <option value="0" style="color:green;">未审核</option>
                    <option value="1" style="color:green;">审核通过</option>
                    <option value="-1" style="color:green;">审核拒绝</option>
                 </select>
            </div>
            <div class="form-group">
                <label for="">开始时间</label>
                <input placeholder="开始时间" class="form-control layer-date" id="startTime">
            </div>
            <div class="form-group">
                <label for="endTime">结束时间</label>
                <input class="form-control layer-date" id="endTime" placeholder="结束时间">
            </div>
            <button id="btn_search" type="button" class="btn btn-primary">
                搜索
            </button>
            <button id="btn_reset" type="button" class="btn btn-primary">
                重置
            </button>
            <button id="btn_add" type="button" class="btn btn-default">
                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
            </button>
            <button id="btn_send" type="button" class="btn btn-default">
                群发短信
            </button>
             <!--<button id="btn_delete" type="button" class="btn btn-default">-->
                <!--<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>删除-->
            <!--</button>-->
        </div>
    </div>

    <table id="tb_dept" >
        <thead>
            <tr>
                <th data-checkbox="true"></th>
                <th data-field="numId">用户id</th>
                <th data-field="name">姓名</th>
                <th data-field="userType" data-formatter="typeFormatter">用户类型</th>
                <th data-field="sex" data-formatter="sexFormatter">性别</th>
                <th data-field="mobile">手机</th>
                <th data-field="inviterName">邀请人</th>
                <th data-field="inviteNumId">邀请人id</th>
                <th data-field="fkGradeId" data-formatter="gradeFormatter">用户等级</th>
                <th data-field="checkFlag" data-formatter="auditStatusFormatter">审核状态</th>
                <th data-field="addTime">创建时间</th>
                <th data-field="operate" data-formatter="operateFormatter">操作</th> 
            </tr>
        </thead>
    </table>

</div>
</body>
<!-- 全局js -->
<script src="../../js/jquery.min.js?v=2.1.4"></script>
<script src="../../js/bootstrap.min.js?v=3.3.6"></script>

<!-- 自定义js -->
<script src="../../js/content.js?v=1.0.0"></script>


<!-- Bootstrap table -->
<script src="../../js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="../../js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="../../js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!--MVVM框架-->
<script type="text/javascript" src="../../js/plugins/knockout/knockout-3.4.2.js"></script>
<script type="text/javascript" src="../../js/plugins/knockout/knockout.mapping-latest.js"></script>

<!-- layerDate plugin javascript -->
<script src="../../js/plugins/layer/laydate/laydate.js"></script>

<script type="text/javascript" src="../../js/common/auth.js"></script>

<script type="text/javascript">
    var __addOrUpdateUrl = "/appMember";//post 更新或添加
    var __addUrl = "/appMember/allAdd";//post 更新或添加
    var __addOrUpdateExpertUrl = "/appExpert";//post 更新或添加
    var __addOrUpdateClinicUrl = "/appDoctor";//post 更新或添加
    var __listUrl = "/appAgent/generalizeMember";  //post 获取列表
    var __listMemberUrl = "/appMember/read/list";//put 获取列表
    var __delUrl = "/appMember"; //delete 方式 删除
	var __getExpertByIdUrl = "/appExpert/read/detail/byId";//post 获取专家附属信息
	var __getClinicUrl = "/appDoctor/read/detail/byId";//get 获取诊所信息
	var __listAreaUrl = "/appArea/read/list/area"; //put 获取列表
	var __getBalanceUrl = "/appMemBalance/read/detail";//get 获取邀请人人信息
	var __upload = "/upload/temp/image/to/oss" ;//图片上传
	var maxHeight = top.document.body.clientHeight * 0.8 ; //文档高度的80%
    //初始化
    $(function () {
        //1、初始化表格
        tableInit.Init();

        //2、注册增删改事件
        operate.operateInit();

        //3、日期初始化
        dateInit.Init();
    });

    var koModel={
        searchModel:{
             mobile:ko.observable(),
             userType:ko.observable(),
             checkFlag:ko.observable(),
             name:ko.observable(),
             numId:ko.observable()
        },
        updatePwdModel:{
            id:ko.observable(),
            mobile:ko.observable(),
            name:ko.observable(),
            updatePwd1:ko.observable(),
            updatePwd2:ko.observable()
        }
    };


	function GetRequest() {
  var url = location.search; //获取url中"?"符后的字串
   var theRequest = new Object();
   if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      strs = str.split("&");
      for(var i = 0; i < strs.length; i ++) {
         theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
      }
   }
   return theRequest;
    }

    //初始化表格
    var tableInit = {
        Init: function () {
            function queryParams(param){
                var unmapped = ko.mapping.toJS(koModel.searchModel);
                var pa = { pageSize: param.limit, pageNum :  param.pageNumber}
                if($("#startTime").val()){
                    pa.startTime = $("#startTime").val();
                }
                if($("#endTime").val()){
                    pa.endTime = $("#endTime").val();
                }
			   
				var Request = new Object();
                Request = GetRequest();
              
                var id = Request['id'];
                pa.fkAgentId = id;
                pa.orderBy = "add_time";
				//return JSON.stringify($.extend(pa,unmapped));
				return $.extend(pa,unmapped);
            }
	
            $("#tb_dept").bootstrapTable({
                url: __listUrl,
                method: 'post',                      //请求方式（*）
                toolbar: '#toolbar',                //工具按钮用哪个容器
                queryParams: queryParams,           //传递参数（*）
                pagination: true,                   //是否显示分页（*）
                sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                paginationHAlign:"right",
                uniqueId:"id",
                pageNumber: 1,                      //初始化加载第一页，默认第一页
                pageSize: 10,                       //每页的记录行数（*）
                pageList: [10, 25, 50, 100],       //可供选择的每页的行数（*）
                search: false,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                strictSearch: true,
                showColumns: true,                  //是否显示所有的列
                cache:false,
                showRefresh: true,                  //是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                showToggle: false,
                responseHandler:function(res){
                    if(res.code==401){
                        top.window.location.href=top.window.location.origin+"/login.html";
                    }
                    return {
                        "total":res.total,
                        "rows":res.data
                    }
                }
            });
        }
    };

    /**
     每行的操作按钮
     */
    function operateFormatter(value, row, index){
    	var html =  '<button  type="button" class="btn btn-default" onclick="operate.operateDelete(\''+row.id+'\')">删除</button>';
    	if(row.userType==2||row.userType==3){
    		html+='&nbsp;&nbsp;<button  type="button" class="btn btn-default" onclick="operate.auditUser(\''+row.id+'\')">审核</button>';
    	}
    	if(row.userType==3){
    		html+='&nbsp;&nbsp;<button  type="button" class="btn btn-default" onclick="operate.updateExpert(\''+row.id+'\')">修改专家信息</button>';
    		html+='&nbsp;&nbsp;<button  type="button" class="btn btn-default" onclick="operate.operateComment(\'' + row.id + '\')">评论</button>' ;
    	}
    	if(row.userType==1){
    		html+='&nbsp;&nbsp;<button  type="button" class="btn btn-default" onclick="operate.updateOrg(\''+row.id+'\')">修改诊所信息</button>';
    	}
        html+='&nbsp;&nbsp;<button  type="button" class="btn btn-default" onclick="operate.updatePwd(\''+row.id+'\')">修改密码</button>';
        html+='&nbsp;&nbsp;<button  type="button" class="btn btn-default" onclick="operate.operateUpdate(\''+row.id+'\')">修改</button>';
        html+='&nbsp;&nbsp;<button  type="button" class="btn btn-default" onclick="operate.getList(\''+row.id+'\')">详情</button>';
        html+='&nbsp;&nbsp;<button  type="button" class="btn btn-default" onclick="operate.balance(\''+row.id+'\')">查看账目</button>';
        html+='&nbsp;&nbsp;<button  type="button" class="btn btn-default" onclick="operate.sendMsg(\''+row.mobile+'\')">发送短信</button>';
        return html;
    }

    function typeFormatter(value, row, index){
		if(value&&value==3){
			return "<font color='red'>专家</font>";
		}else if(value&&value==2){
			return "医生经纪人";
		}else{
			return "基层医生";
		}
    }
    
    function sexFormatter(value, row, index){
		if(value&&value=="M"){
			return "男";
		}else{
			return "女";
		}
    }
    
    function gradeFormatter(value, row, index){
		if(value&&value=="43cce4d1bc354c3eb78d7d8a3f1346c8"){
			return "白金会员";
		}else if(value=="43cce4e1bc354a3eb78d7d8a3f1346c8"){
			return "钻石会员";
		}else{
			return "普通会员";
		}
    }
    
    function auditStatusFormatter(value, row, index){
    	if(row.userType==2||row.userType==3){
    		if(value&&value==-1){
    			return "<font color='red'>审核拒绝</font>";
    		}else if(value&&value==1){
    			return "审核通过";
    		}else{
    			return "未审核";
    		}
    	}else{
    		return "";
    	}
    }

	function getTable(){
		return $("#tb_dept");
	}
    function getSelections(){
        return getTable().bootstrapTable('getSelections');
    }
    function refreshTable(){
        getTable().bootstrapTable("refresh");
    }
	
	//群发短信
    $('#btn_send').on("click", function () {
    	var mobiles = [];
    	top.layer.open({
    		title:"群发信息",
            type: 1,
            area: "500px",
            maxHeight:maxHeight,
            content:$get("./sendMsg.html"),
            btn: ["发送", "取消"],
            yes: function(index, layerDom){
            	var close = top.layer.load(1);
            	var text = $("#msg",$(layerDom)).val();
                $$ajax({
                	headers:{
                		Accept:'application/json;charset=utf-8'
                		},
		            url: "/message",
		            type: "POST",
		            dataType:'json',
		            contentType:"application/x-www-form-urlencoded;charset=utf-8",
		            data:{mobileList:mobiles,text:text},
		            success: function (response) {
	                 	if(response.httpCode==200){
	                 		top.layer.close(close);
	                 		console.log(response.data);
	                 		top.layer.close(index);
	                 		top.layer.alert("发送成功",{icon:6});
	                 	}else{
	                 		top.layer.close(close);
	                 		top.layer.close(index);
	                 		alert(response.msg);
	                 	}
		            }
		        });
            },
            btn2:function(index,layarDom){//关闭
                top.layer.close(index);
            },
            success:function(layarDom,index){//弹层加载成功
            	var rows = getTable().bootstrapTable('getAllSelections');
            	if(rows.length==0){
            		if(confirm("确定发送给所有人？")){
            			$$ajax({
		                    url: __listUrl,
		                    type: 'put',//提交的方式
		                    dataType:'json',
		                    async:false,
		                    contentType:"application/json; charset=utf-8",
		                    data:JSON.stringify({}),
		                    success: function(response) {
		                        if (response.httpCode==200) {
		                        	var members = response.data;
		                        	for(var i in members){
		                        		mobiles.push(members[i].mobile);
		                        	}
		                        } else{
		                            alert(response.msg);
		                        }
		                    }
		                });
            		}
            	}else{
            		$("#label",$(layarDom)).html("发给选中的人");
            		for(var i in rows){
            			mobiles.push(rows[i].mobile);
            		}
            	}
            }
    	})
    		
    	
    })
	
	
    //操作
    var operate = {
        //初始化按钮事件
        operateInit: function () {
            this.operateAdd();
            //this.operateUpdate();
            //this.operateDelete();
            this.operateSearch();//搜索清空按钮绑定初始化
            this.entityModel ={
            	headImgurl: ko.observable(),
                mobile: ko.observable(),
                memPassword:ko.observable(),
                email: ko.observable(),
                name: ko.observable(""),
                nickname: ko.observable(),
                status: ko.observable(),
                birthday: ko.observable(),
                otherContacts: ko.observable(),
                address: ko.observable(),
                signature: ko.observable(),
                fkGradeId: ko.observable(),
                sex: ko.observable(),
                inviteId: ko.observable(),
                level: ko.observable(),
                idCardNo: ko.observable(),
                countyId: ko.observable(),
                provinceId: ko.observable(),
                cityId: ko.observable(),
                userType: ko.observable(),
                checkFlag: ko.observable(),
            };
            
            this.expertModel ={
                fkMemId: ko.observable(),
                offImgurl:ko.observable(),
                fcardImgurl: ko.observable(),
                rcardImgurl: ko.observable(""),
                certificateImgurl: ko.observable(),
                status: ko.observable(),
                workingYears: ko.observable(),
                goodat: ko.observable(),
                titles: ko.observable(),
                orderValue: ko.observable(),
                dept: ko.observable(),
                titles: ko.observable(),
                level: ko.observable(),
                rate: ko.observable(),
                levelaPrice: ko.observable(),
                orgImgurl: ko.observable(),
                orgName: ko.observable(),
                orgGrade: ko.observable(),
                orgProvinceId: ko.observable(),
                orgCityId: ko.observable(),
                orgCountyId: ko.observable(),
                orgAddress: ko.observable()
            };
            
            this.clinicModel ={
                fkMemId: ko.observable(),
                clinicsImgurl:ko.observable(),
                clinicsName: ko.observable(),
                openTime: ko.observable(),
                drAddress: ko.observable(),
                drProvinceId: ko.observable(),
                drCityId: ko.observable(),
                drCountyId: ko.observable(),
                status: ko.observable(),
            };
            

        },
        
        sendMsg:function(mobile){
        	top.layer.open({
        		title:"个人发短信",
                type: 1,
                area: "500px",
                maxHeight:maxHeight,
                content:$get("./sendMsg.html"),
                btn: ["发送", "取消"],
                yes: function(index, layerDom){
                	var close = top.layer.load(1);
                	var text = $("#msg",$(layerDom)).val();
                	var mobiles = [];
                	mobiles.push(mobile);
	                $$ajax({
	                	headers:{
                			Accept:'application/json;charset=utf-8'
                		},
			            url: "/message",
			            type: "POST",
			            dataType:'json',
			            contentType:"application/x-www-form-urlencoded;charset=utf-8",
			            data:{mobileList:mobiles,text:text},
			            success: function (response) {
		                 	if(response.httpCode==200){
		                 		top.layer.close(close);
		                 		console.log(response.data);
		                 		top.layer.close(index);
		                 		top.layer.alert("发送成功",{icon:6});
		                 	}else{
		                 		top.layer.close(close);
		                 		top.layer.close(index);
		                 		alert(response.msg);
		                 	}
			            }
			        });
                },
                btn2:function(index,layarDom){//关闭
                    top.layer.close(index);
                },
                success:function(layarDom,index){
                	$("#label",$(layarDom)).html("发给一个人");
                }//弹层加载成功
        	})
        },
        
        //新增
        operateAdd: function(){
        	var newClinic = null;
        	var newExpert = null;
            $('#btn_add').on("click", function () {
                var newModel =   operate.entityModel;
                top.layer.open({
                    title:"app用户新增",
                    type: 1,
                    area: "500px",
                    maxHeight:maxHeight,
                    content:$get("./addMember.html"),
                    btn: ["保存", "取消"],
                    yes: function(index, layerDom){
                    	var close = top.layer.load(1);
                    	//头像上传
				        upload("headImg",newModel.headImgurl,layerDom,__upload);
                        var member = ko.mapping.toJS(newModel);
                        if(!operate.operateCheck(member)){
                            return;
                        }
                        $$ajax({
                            url: __addUrl,
                            type: 'post',//提交的方式
                            dataType:'json',
                            contentType:"application/json; charset=utf-8",
                            data:JSON.stringify({"member":member,"clinic":newClinic,"expert":newExpert}),
                            success: function(response) {
                                console.log(response.msg)
                                if (response.httpCode==200) {
                                	top.layer.close(close);
                                	refreshTable();
		                    		top.layer.alert("添加成功",{icon:6});
                                	top.layer.close(index);
                                } else{
                                	top.layer.close(close);
                                    alert(response.msg);
                                }
                            }

                        });

                    },
                    btn2:function(index,layarDom){//关闭
                        ko.cleanNode(layarDom.get(0));
                    },
                    success:function(layarDom,index){//弹层加载成功
                    	$("#userType",$(layarDom)).change(function(){
                    		var userType = $(this).val();
                    		if(userType==1){
	                    		top.layer.open({
				                    title:"诊所信息新增",
				                    type: 2,
				                    area: ["500px","800px"],
				                    content:'html/app_member/addClinic.html',
				                    zIndex: top.layer.zIndex, //重点1
				                    btn: ["保存"],
				                    yes: function(index, layerDom){
				                    	var iframeWin = $("iframe",$(layerDom))[0].contentWindow;
				                    	newClinic = iframeWin.getObj();
				                    	if(!operate.operateClinicCheck(newClinic)){
									        return;
									    }
				                    	top.layer.close(index);
				                    },
				                    success:function(layarDom,index){//弹层加载成功
				                    	//设置弹框置顶
				                    	top.layer.setTop(layarDom); //重点2
				                    }
				                });
                    		}else if(userType==3){
	                    		top.layer.open({
				                    title:"专家信息新增",
				                    type: 2,
				                    area: ["500px","800px"],
				                    maxHeight:maxHeight,
				                    content:'html/app_member/addExpert.html',
				                    zIndex: top.layer.zIndex, //重点1
				                    btn: ["保存"],
				                    yes: function(index, layerDom){
				                    	var iframeWin = $("iframe",$(layerDom))[0].contentWindow;
				                    	newExpert = iframeWin.getObj();
				                    	if(!operate.operateExpertCheck(newExpert)){
								            return;
								        }
				                    	top.layer.close(index);
				                    },
				                    success:function(layarDom,index){//弹层加载成功
				                    	//设置弹框置顶
				                    	top.layer.setTop(layarDom); //重点2
				                    }
				                });
                    		}
                    	})
                    	
                    	//获取上传文件的路径并预览
                    	preview("headImg",layarDom);
                    	
						var birthday = $("#birthday", $(layarDom)).get(0);
                        top.laydate.render(dateInit.customInitLayDate(birthday));
                        //获取省份
                        $$ajax({
                            url: __listAreaUrl,
                            type: 'post',//提交的方式
                            dataType:'json',
                            async:false,
                            success: function(response) {
                                console.log(response.msg)
                                if (response.httpCode==200) {
                                	var arr = response.data;
                                	var province = $("#provinceId",$(layarDom));
                                	for(var i in arr){
                                		province.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
                                	}
                                } else{
                                    alert(response.msg);
                                }
                            }

                        });
                        
                        $("#provinceId",$(layarDom)).change(function(){
                        	var provinceVal = $(this).val();
                        	if(provinceVal==""){
                        		return ;
                        	}
	                    	//获取相应省份的城市
	                        $$ajax({
	                            url: __listAreaUrl,
	                            type: 'post',//提交的方式
	                            dataType:'json',
	                            data:{pid:provinceVal},
	                            success: function(response) {
	                                console.log(response.msg)
	                                if (response.httpCode==200) {
	                                	var arr = response.data;
	                                	var city = $("#cityId",$(layarDom));
	                                	city.find("option:gt(0)").remove();
	                                	for(var i in arr){
	                            			city.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
	                                	}
	                                } else{
	                                    alert(response.msg);
	                                }
	                            }
	                        });
                        })
                        
                        $("#cityId",$(layarDom)).change(function(){
                        	var cityVal = $(this).val();
                        	if(cityVal==""){
                        		return ;
                        	}
	                    	//获取相应城市的区域
	                        $$ajax({
	                            url: __listAreaUrl,
	                            type: 'post',//提交的方式
	                            dataType:'json',
	                            data:{pid:cityVal},
	                            success: function(response) {
	                                console.log(response.msg)
	                                if (response.httpCode==200) {
	                                	var arr = response.data;
	                                	var area = $("#countyId",$(layarDom));
	                                	area.find("option:gt(0)").remove();
	                                	for(var i in arr){
	                            			area.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
	                                	}
	                                } else{
	                                    alert(response.msg);
	                                }
	                            }
	                        });
                        })
                        
                        function formatMemberParams(param) {
                            return JSON.stringify({ pageNum: 1, pageSize: 10, name: param.name });
                        }
                        
                        //添加邀请人自动提示
                        top.$("#inviteSearch", top.$(layarDom)).autocomplete({
                            serviceUrl: __listMemberUrl,
                            type: "put",
                            paramName: "name",
                            queryParam: formatMemberParams,
                            zIndex:268000000,
                            ajaxSettings: {
                                contentType: "application/json; charset=utf-8",
                                dataType: "JSON"
                            },
                            transformResult: function (response) {
                                console.log(response.data )
                                var bbs = {
                                    suggestions: top.$.map(response.data, function(dataItem) {
                                        return { value: dataItem.name,id:dataItem.id};
                                    })
                                };
                                return bbs; 
                            },
                            onSelect: function (suggestion) {
                                console.log(suggestion)
                                newModel.inviteId(suggestion.id);
                            }
                        });
                        
                        ko.applyBindings(newModel, $(layarDom).get(0));
                        //var unmapped = ko.mapping.toJS(operate.entityModel);
                    }
                });
            });
        },
        //编辑修改
        operateUpdate: function (id) {
        	var newClinic = null;
        	var newExpert = null;
			var row = getTable().bootstrapTable("getRowByUniqueId",id);
            var newModel =   ko.mapping.fromJS(row);
            var provinceValue = row.provinceId;
            var cityValue = row.cityId;
            top.layer.open({
                title:"app用户信息修改",
                type: 1,
                area: "500px",
                maxHeight:maxHeight,
                content:$get("./updateMember.html"),
                btn: ["保存", "取消"],
                yes: function(index, layerDom){
                	var close = top.layer.load(1);
                	var value = row.mobile;
                	var change = $("#mobile",$(layerDom)).val();
                	var arr = [];
            		if(change!=value){
            			$$ajax({
	                        url: __listUrl,
	                        type: 'put',//提交的方式
	                        dataType:'json',
	                        async:false,
	                        contentType:"application/json; charset=utf-8",
	                        data:JSON.stringify({mobile:change}),
	                        success: function(response) {
	                            console.log(response.msg)
	                            if (response.httpCode==200) {
	                                arr = response.data;
	                            } else{
	                                alert(data.msg);
	                            }
	                        }
	                    });
            		}
                	if(arr.length>0){
                    	top.layer.close(close);
                    	top.layer.alert("此手机号已被注册！");
                    	return ;
                    }
                	//头像上传
			        upload("headImg",newModel.headImgurl,layerDom,__upload);
                    var member = ko.mapping.toJS(newModel);
                    if(!operate.operateCheck(member)){
                    	top.layer.close(close);
                        return;
                    }
                    $$ajax({
                        url: __addUrl,
                        type: 'post',//提交的方式
                        dataType:'json',
                        contentType:"application/json; charset=utf-8",
                        data:JSON.stringify({"member":member,"clinic":newClinic,"expert":newExpert}),
                        success: function(data) {
                            console.log(data.msg)
                            if (data.httpCode==200) {
                            	top.layer.close(close);
                                refreshTable();
		                		top.layer.close(index);
	                    		top.layer.alert("更新成功",{icon:6});
                            } else{
                            	top.layer.close(close);
                                alert(data.msg);
                            }
                        }
                    });

                },
                btn2:function(index,layarDom){//关闭
                    ko.cleanNode(layarDom.get(0));
                },
                success:function(layarDom,index){//弹层加载成功
                	
                	$("#userType",$(layarDom)).change(function(){
                		var userType = $(this).val();
                		if(userType==1){
                    		top.layer.open({
			                    title:"诊所信息新增",
			                    type: 2,
			                    area: ["500px","800px"],
			                    content:'html/app_member/addClinic.html',
			                    zIndex: top.layer.zIndex, //重点1
			                    btn: ["保存"],
			                    yes: function(index, layerDom){
			                    	var iframeWin = $("iframe",$(layerDom))[0].contentWindow;
			                    	newClinic = iframeWin.getObj();
			                    	top.layer.close(index);
			                    },
			                    success:function(layarDom,index){//弹层加载成功
			                    	//设置弹框置顶
			                    	top.layer.setTop(layarDom); //重点2
			                    }
			                });
                		}else if(userType==3){
                    		top.layer.open({
			                    title:"专家信息新增",
			                    type: 2,
			                    area: ["500px","800px"],
			                    maxHeight:maxHeight,
			                    content:'html/app_member/addExpert.html',
			                    zIndex: top.layer.zIndex, //重点1
			                    btn: ["保存"],
			                    yes: function(index, layerDom){
			                    	var iframeWin = $("iframe",$(layerDom))[0].contentWindow;
			                    	newExpert = iframeWin.getObj();
			                    	top.layer.close(index);
			                    },
			                    success:function(layarDom,index){//弹层加载成功
			                    	//设置弹框置顶
			                    	top.layer.setTop(layarDom); //重点2
			                    }
			                });
                		}
                	})
                	
                	//获取邀请人信息
				    $("#inviteSearch",$(layarDom)).val(row.inviterName);
                	//获取上传文件的路径并预览
					preview("headImg",layarDom);                	
                	var birthday = $("#birthday", $(layarDom)).get(0);
                    top.laydate.render(dateInit.customInitLayDate(birthday));
                    
                    //获取省份
                    $$ajax({
                        url: __listAreaUrl,
                        type: 'post',//提交的方式
                        dataType:'json',
                        async:false,
                        success: function(response) {
                            console.log(response.msg)
                            if (response.httpCode==200) {
                            	var arr = response.data;
                            	var province = $("#provinceId",$(layarDom));
                            	for(var i in arr){
                            		province.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
                            	}
                            } else{
                                alert(response.msg);
                            }
                        }

                    });
                    
                    if(provinceValue){
                    	$$ajax({
	                        url: __listAreaUrl,
	                        type: 'post',//提交的方式
	                        dataType:'json',
	                        async:false,
	                        data:{pid:provinceValue},
	                        success: function(response) {
	                            console.log(response.msg)
	                            if (response.httpCode==200) {
	                            	var arr = response.data;
	                            	var city = $("#cityId",$(layarDom));
	                            	city.find("option:gt(0)").remove();
	                            	for(var i in arr){
	                        			city.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
	                            	}
	                            } else{
	                                alert(response.msg);
	                            }
	                        }
	                    });
                    }
                    
                    
                    if(cityValue){
                    	$$ajax({
	                        url: __listAreaUrl,
	                        type: 'post',//提交的方式
	                        dataType:'json',
	                        async:false,
	                        data:{pid:cityValue},
	                        success: function(response) {
	                            console.log(response.msg)
	                            if (response.httpCode==200) {
	                            	var arr = response.data;
	                            	var area = $("#countyId",$(layarDom));
	                            	area.find("option:gt(0)").remove();
	                            	for(var i in arr){
	                        			area.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
	                            	}
	                            } else{
	                                alert(response.msg);
	                            }
	                        }
	                    });
                    }
                	
                    
                    $("#provinceId",$(layarDom)).change(function(){
                    	var provinceVal = $(this).val();
                    	if(provinceVal==""){
                    		return;
                    	}
                    	//获取相应省份的城市
                        $$ajax({
                            url: __listAreaUrl,
                            type: 'post',//提交的方式
                            dataType:'json',
                            async:false,
                            data:{pid:provinceVal},
                            success: function(response) {
                                console.log(response.msg)
                                if (response.httpCode==200) {
                                	var arr = response.data;
                                	var city = $("#cityId",$(layarDom));
                                	city.find("option:gt(0)").remove();
                                	for(var i in arr){
                            			city.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
                                	}
                                } else{
                                    alert(response.msg);
                                }
                            }
                        });
                    })
                    
                    $("#cityId",$(layarDom)).change(function(){
                    	var cityVal = $(this).val();
                    	if(cityVal==""){
                    		return;
                    	}
                    	//获取相应城市的区域
                        $$ajax({
                            url: __listAreaUrl,
                            type: 'post',//提交的方式
                            dataType:'json',
                            async:false,
                            data:{pid:cityVal},
                            success: function(response) {
                                console.log(response.msg)
                                if (response.httpCode==200) {
                                	var arr = response.data;
                                	var area = $("#countyId",$(layarDom));
                                	area.find("option:gt(0)").remove();
                                	for(var i in arr){
                            			area.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
                                	}
                                } else{
                                    alert(response.msg);
                                }
                            }
                        });
                    })
                	function formatMemberParams(param) {
                        return JSON.stringify({ pageNum: 1, pageSize: 10, name: param.name });
                    }
                    
                    //添加邀请人自动提示
                    top.$("#inviteSearch", top.$(layarDom)).autocomplete({
                        serviceUrl: __listMemberUrl,
                        type: "put",
                        paramName: "name",
                        queryParam: formatMemberParams,
                        zIndex:268000000,
                        ajaxSettings: {
                            contentType: "application/json; charset=utf-8",
                            dataType: "JSON"
                        },
                        transformResult: function (response) {
                            console.log(response.data )
                            var bbs = {
                                suggestions: top.$.map(response.data, function(dataItem) {
                                    return { value: dataItem.name,id:dataItem.id};
                                })
                            };
                            return bbs; 
                        },
                        onSelect: function (suggestion) {
                            console.log(suggestion)
                            newModel.inviteId(suggestion.id);
                        }
                    });
                	
                    ko.applyBindings(newModel, layarDom.get(0));
                    //var unmapped = ko.mapping.toJS(operate.entityModel);
                }
            });

        },
        //修改专家信息
        updateExpert:function(id){
        	var expert ;
        	$$ajax({
                url: __getExpertByIdUrl,
                type: 'post',//提交的方式
                dataType:'json',
                async:false,
                data:{id:id},
                success: function(response) {
                    console.log(response.msg)
                    if (response.httpCode==200) {
                    	if(response.data){
                    		expert = response.data;
                    		var newModel = ko.mapping.fromJS(expert);
				        	top.layer.open({
				                title:"修改专家信息",
				                type: 1,
				                area: "500px",
					            maxHeight: maxHeight,
				                content:$get("./updateExpert.html"),
				                btn: ["保存", "取消"],
				                yes: function(index, layerDom){
				                	var close = top.layer.load(1);
				                	//文件上传
				                	//标准照上传
				                	upload("offImg",newModel.offImgurl,layerDom,__upload);
				                	//身份证正面
				                	upload("fcardImg",newModel.fcardImgurl,layerDom,__upload);
				                	//身份证反面
				                	upload("rcardImg",newModel.rcardImgurl,layerDom,__upload);
				                	//资质证书
				                	upload("certificateImg",newModel.certificateImgurl,layerDom,__upload);
				                	//单位照片
				                	upload("orgImg",newModel.orgImgurl,layerDom,__upload);
				                	
				                    var jsModle = ko.mapping.toJS(newModel);
				                    if(!operate.operateExpertCheck(jsModle)){
				                    	top.layer.close(close);
				                        return;
				                    }
				                    $$ajax({
				                        url: __addOrUpdateExpertUrl,
				                        type: 'post',//提交的方式
				                        dataType:'json',
				                        contentType:"application/json; charset=utf-8",
				                        data:JSON.stringify(jsModle),
				                        success: function(data) {
				                            console.log(data.msg)
				                            if (data.httpCode==200) {
				                            	top.layer.close(close);
				                                top.layer.alert("更新成功",{icon:6});
				                                refreshTable();
				                                top.layer.close(index);
				                            } else{
				                            	top.layer.close(close);
				                                alert(data.msg);
				                            }
				                        }
				                    });
				
				                },
				                btn2:function(index,layarDom){//关闭
				                    ko.cleanNode(layarDom.get(0));
				                },
				                success:function(layerDom,index){//弹层加载成功
				                	
				                	//获取上传文件的路径并预览
					        		preview("offImg",layerDom);
					           
					        		preview("fcardImg",layerDom);
					        	
					        		preview("rcardImg",layerDom);
					        	
					        		preview("certificateImg",layerDom);
					        		
					        		preview("orgImg",layerDom);
					        		
					        		//获取省份
				                    $$ajax({
				                        url: __listAreaUrl,
				                        type: 'post',//提交的方式
				                        dataType:'json',
				                        async:false,
				                        success: function(response) {
				                            console.log(response.msg)
				                            if (response.httpCode==200) {
				                            	var arr = response.data;
				                            	var province = $("#orgProvinceId",$(layerDom));
				                            	for(var i in arr){
				                            		province.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
				                            	}
				                            	
				                            	
				                            } else{
				                                alert(response.msg);
				                            }
				                        }
				
				                    });
				                    
				                    if(expert.orgProvinceId){
				                    	$$ajax({
					                        url: __listAreaUrl,
					                        type: 'post',//提交的方式
					                        dataType:'json',
					                        async:false,
					                        data:{pid:expert.orgProvinceId},
					                        success: function(response) {
					                            console.log(response.msg)
					                            if (response.httpCode==200) {
					                            	var arr = response.data;
					                            	var city = $("#orgCityId",$(layerDom));
					                            	city.find("option:gt(0)").remove();
					                            	for(var i in arr){
					                        			city.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
					                            	}
					                            } else{
					                                alert(response.msg);
					                            }
					                        }
					                    });
				                    }
				                    
				                    
				                    if(expert.orgCityId){
				                    	$$ajax({
					                        url: __listAreaUrl,
					                        type: 'post',//提交的方式
					                        dataType:'json',
					                        async:false,
					                        data:{pid:expert.orgCityId},
					                        success: function(response) {
					                            console.log(response.msg)
					                            if (response.httpCode==200) {
					                            	var arr = response.data;
					                            	var area = $("#orgCountyId",$(layerDom));
					                            	area.find("option:gt(0)").remove();
					                            	for(var i in arr){
					                        			area.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
					                            	}
					                            } else{
					                                alert(response.msg);
					                            }
					                        }
					                    });
				                    }
				                	
				                    
				                    $("#orgProvinceId",$(layerDom)).change(function(){
				                    	var provinceVal = $(this).val();
				                    	if(provinceVal==""){
				                    		return;
				                    	}
				                    	//获取相应省份的城市
				                        $$ajax({
				                            url: __listAreaUrl,
				                            type: 'post',//提交的方式
				                            dataType:'json',
				                            async:false,
				                            data:{pid:provinceVal},
				                            success: function(response) {
				                                console.log(response.msg)
				                                if (response.httpCode==200) {
				                                	var arr = response.data;
				                                	var city = $("#orgCityId",$(layerDom));
				                                	city.find("option:gt(0)").remove();
				                                	for(var i in arr){
				                            			city.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
				                                	}
				                                } else{
				                                    alert(response.msg);
				                                }
				                            }
				                        });
				                    })
				                    
				                    $("#orgCityId",$(layerDom)).change(function(){
				                    	var cityVal = $(this).val();
				                    	if(cityVal==""){
				                    		return;
				                    	}
				                    	//获取相应城市的区域
				                        $$ajax({
				                            url: __listAreaUrl,
				                            type: 'post',//提交的方式
				                            dataType:'json',
				                            async:false,
				                            data:{pid:cityVal},
				                            success: function(response) {
				                                console.log(response.msg)
				                                if (response.httpCode==200) {
				                                	var arr = response.data;
				                                	var area = $("#orgCountyId",$(layerDom));
				                                	area.find("option:gt(0)").remove();
				                                	for(var i in arr){
				                            			area.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
				                                	}
				                                } else{
				                                    alert(response.msg);
				                                }
				                            }
				                        });
				                    })
					            	
				                	ko.applyBindings(newModel, layerDom.get(0));
				                }
				            });
                    	}else{
                    		top.layer.alert("暂没有相关信息",{icon:5});
                    	}
                    } else{
                        alert(response.msg);
                    }
                }
            });
        },
        
        
        //修改诊所信息
        updateOrg:function(id){
        	var clinic ;
        	$$ajax({
	            url: __getClinicUrl,
	            type: 'post',//提交的方式
	            dataType:'json',
	            async:false,
	            data:{id:id},
	            success: function(response) {
	                console.log(response.msg)
	                if (response.httpCode==200) {
	                	if(response.data){
	                		clinic = response.data;
	                		var newModel = ko.mapping.fromJS(clinic);
				        	top.layer.open({
				                title:"诊所详情",
				                type: 1,
				                area: "500px",
					            maxHeight: maxHeight,
				                content:$get("./updateClinic.html"),
				                btn: ["保存", "取消"],
				                yes: function(index, layerDom){
				                	var close = top.layer.load(1);
				                	//诊所门头照上传
							        upload("clinicsImg",newModel.ogrblpice,layerDom,__upload);
				                	
				                    var jsModle = ko.mapping.toJS(newModel);
				                    if(!operate.operateClinicCheck(jsModle)){
				                    	top.layer.close(close);
				                        return;
				                    }
				                    $$ajax({
				                        url: __addOrUpdateClinicUrl,
				                        type: 'post',//提交的方式
				                        dataType:'json',
				                        contentType:"application/json; charset=utf-8",
				                        data:JSON.stringify(jsModle),
				                        success: function(data) {
				                            console.log(data.msg)
				                            if (data.httpCode==200) {
				                            	top.layer.close(close);
				                                top.layer.alert("更新成功",{icon:6});
				                                refreshTable();
				                                top.layer.close(index);
				                            } else{
				                            	top.layer.close(close);
				                                alert(data.msg);
				                            }
				                        }
				                    });
				
				                },
				                btn2:function(index,layarDom){//关闭
				                    ko.cleanNode(layarDom.get(0));
				                },
				                success:function(layerDom,index){//弹层加载成功
				                	var openTime = $("#openTime", $(layerDom)).get(0);
				                    top.laydate.render(dateInit.customInitLayDate(openTime));
				                	//获取上传文件的路径并预览
					        		preview("ogrblpice",layerDom);
					        		preview("orgpic",layerDom);
					        		//获取省份
				                    $$ajax({
				                        url: __listAreaUrl,
				                        type: 'post',//提交的方式
				                        dataType:'json',
				                        async:false,
				                        success: function(response) {
				                            console.log(response.msg)
				                            if (response.httpCode==200) {
				                            	var arr = response.data;
				                            	var province = $("#drProvinceId",$(layerDom));
				                            	for(var i in arr){
				                            		province.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
				                            	}
				                            	
				                            	
				                            } else{
				                                alert(response.msg);
				                            }
				                        }
				
				                    });
				                    
				                    if(clinic.drProvinceId){
				                    	$$ajax({
					                        url: __listAreaUrl,
					                        type: 'post',//提交的方式
					                        dataType:'json',
					                        async:false,
					                        data:{pid:clinic.drProvinceId},
					                        success: function(response) {
					                            console.log(response.msg)
					                            if (response.httpCode==200) {
					                            	var arr = response.data;
					                            	var city = $("#drCityId",$(layerDom));
					                            	city.find("option:gt(0)").remove();
					                            	for(var i in arr){
					                        			city.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
					                            	}
					                            } else{
					                                alert(response.msg);
					                            }
					                        }
					                    });
				                    }
				                    
				                    
				                    if(clinic.drCityId){
				                    	$$ajax({
					                        url: __listAreaUrl,
					                        type: 'post',//提交的方式
					                        dataType:'json',
					                        async:false,
					                        data:{pid:clinic.drCityId},
					                        success: function(response) {
					                            console.log(response.msg)
					                            if (response.httpCode==200) {
					                            	var arr = response.data;
					                            	var area = $("#drCountyId",$(layerDom));
					                            	area.find("option:gt(0)").remove();
					                            	for(var i in arr){
					                        			area.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
					                            	}
					                            } else{
					                                alert(response.msg);
					                            }
					                        }
					                    });
				                    }
				                	
				                    
				                    $("#drProvinceId",$(layerDom)).change(function(){
				                    	var provinceVal = $(this).val();
				                    	if(provinceVal==""){
				                    		return;
				                    	}
				                    	//获取相应省份的城市
				                        $$ajax({
				                            url: __listAreaUrl,
				                            type: 'post',//提交的方式
				                            dataType:'json',
				                            async:false,
				                            data:{pid:provinceVal},
				                            success: function(response) {
				                                console.log(response.msg)
				                                if (response.httpCode==200) {
				                                	var arr = response.data;
				                                	var city = $("#drCityId",$(layerDom));
				                                	city.find("option:gt(0)").remove();
				                                	for(var i in arr){
				                            			city.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
				                                	}
				                                } else{
				                                    alert(response.msg);
				                                }
				                            }
				                        });
				                    })
				                    
				                    $("#drCityId",$(layerDom)).change(function(){
				                    	var cityVal = $(this).val();
				                    	if(cityVal==""){
				                    		return;
				                    	}
				                    	//获取相应城市的区域
				                        $$ajax({
				                            url: __listAreaUrl,
				                            type: 'post',//提交的方式
				                            dataType:'json',
				                            async:false,
				                            data:{pid:cityVal},
				                            success: function(response) {
				                                console.log(response.msg)
				                                if (response.httpCode==200) {
				                                	var arr = response.data;
				                                	var area = $("#drCountyId",$(layerDom));
				                                	area.find("option:gt(0)").remove();
				                                	for(var i in arr){
				                            			area.append("<option value='"+arr[i].id+"' style='color:green'>"+arr[i].areaName+"</option>")
				                                	}
				                                } else{
				                                    alert(response.msg);
				                                }
				                            }
				                        });
				                    })
					        	
				                	ko.applyBindings(newModel, layerDom.get(0));
				                }
				            });
	                	}else{
	                		top.layer.alert("暂没有相关信息",{icon:5});
	                	}
	                } else{
	                    alert(response.msg);
	                    //location.reload();
	                }
	            }
 			})
        	
        	
        },
        
        //获取详情
        getList: function (id) {
            var row = getTable().bootstrapTable("getRowByUniqueId",id);
            if(row.sex=="M"){
            	row.sex="男";
            }else{
            	row.sex="女";
            }
            
            switch(row.fkGradeId){
            	case "43cce4d1bc354c3eb78d7d8a3f1346c8" :
            		row.fkGradeId = "白金会员";
            		break;
            	case "43cce4e1bc354a3eb78d7d8a3f1346c8" :
            		row.fkGradeId = "钻石会员";
            		break;
            	default :
            		row.fkGradeId = "普通会员";
            		break;
            }
            
            switch(row.userType){
            	case "1" :
            		row.userType = "基层医生";
            		break;
            	case "2" :
            		row.userType = "医生经纪人";
            		break;
            	default :
            		row.userType = "讲师专家";
            		break;
            }
            var newModel = ko.mapping.fromJS(row);
            
            top.layer.open({
                title:"用户详情",
                type: 1,
                area: "500px",
	            maxHeight: maxHeight,
                content:$get("./detail.html"),
                success:function(layerDom,index){//弹层加载成功
                	ko.applyBindings(newModel, layerDom.get(0));
                }
            });
        },
        //查看评论
        operateComment:function(id){
        	var row = getTable().bootstrapTable("getRowByUniqueId", id);
        	var name = row.name;
        	var url = encodeURI("html/app_comment/list.html?id="+id+"&name="+name+"&type=3");
        	var content = encodeURI(url);
            top.layer.open({
            	title: "课程评论",
            	type: 2,
            	area: ["1000px","600px"],
            	maxHeight:maxHeight,
            	content : content,
            });
        },
        //查看账单
        balance:function(id){
        	var row = getTable().bootstrapTable("getRowByUniqueId", id);
        	var balanceModel ;
        	$$ajax({
                url: __getBalanceUrl,
                type: 'put',//提交的方式
                dataType:'json',
                contentType:"application/json; charset=utf-8",
                async:false,
                data:JSON.stringify({fkMemId:id}),
                success: function(response) {
                    console.log(response.msg)
                    if (response.httpCode==200) {
                    	balanceModel = response.data;
                    } else{
                        alert(data.msg);
                    }
                }
            });
            var model = ko.mapping.fromJS(balanceModel);
            top.layer.open({
            	title: "用户账目",
            	type: 1,
            	area: "400px",
            	maxHeight:maxHeight,
            	content : $get("./balance.html"),
            	success:function(layerDom,index){//弹层加载成功
                	ko.applyBindings(model, layerDom.get(0));
                	$("#name",$(layerDom)).val(row.name);
                }
            });
        },
        //
        //单条删除(假删：把状态改为删除)
        operateDelete: function (id) {
        	if(confirm("确认删除？")){
        		var close = top.layer.load(1);
        		$$ajax({
                    url: __addOrUpdateUrl,
                    type: 'post',//提交的方式
                    dataType:'json',
                    contentType:"application/json; charset=utf-8",
                    data:JSON.stringify({id:id,status:-1}),
                    success: function(data) {
                        console.log(data.msg)
                        if (data.httpCode==200) {
                        	top.layer.close(close);
                            top.layer.alert("删除成功");
                            refreshTable();
                        } else{
                        	top.layer.close(close);
                            alert(data.msg);
                        }
                    }
                });
        	}
            /*$$ajax({
                url: __delUrl,
                type: "DELETE",
                contentType: 'application/json',
                data: JSON.stringify({id:id}),
                success: function (data, status) {
                    if(data.httpCode==200){
                        alert("删除成功!");
                        refreshTable();
                    }else{
                        alert(data.msg);
                    }
                    //tableInit.myViewModel.refresh();
                }
            });*/
        },
        //修改用户密码
        updatePwd:function(id){
            var row = getTable().bootstrapTable("getRowByUniqueId",id);
            var newModel =  $.extend(true,{},koModel.updatePwdModel);
            newModel.mobile(row.mobile);
            newModel.id(row.id);
            newModel.name(row.name);
            top.layer.open({
                title:"修改用户密码",
                type: 1,
                area: "500px",
                maxHeight:maxHeight,
                content:$get("./updatePwd.html"),
                btn: ["保存", "取消"],
                yes: function(index, layerDom){
                	var close = top.layer.load(1);
                    var jsModle = ko.mapping.toJS(newModel);
                    var pass = "^[A-Za-z0-9]{1,}$";
                    if(!jsModle.updatePwd1||!jsModle.updatePwd2){
                    	top.layer.close(close);
                        top.layer.alert('密码不能为空或空格!', {icon: 6});
                        return;
                    }
                    if(!jsModle.updatePwd1.match(pass)){
                    	top.layer.close(close);
                        top.layer.alert('密码只能是数字与字母组成!', {icon: 6});
                        return;
                    }
                    if(jsModle.updatePwd1 != jsModle.updatePwd2){
                    	top.layer.close(close);
                        top.layer.alert('密码不一致，请输入正确密码!', {icon: 6});
                        return;
                    }
                    var dataUpdate={id:jsModle.id,memPassword:jsModle.updatePwd1};
                    $$ajax({
                        url: __addOrUpdateUrl,
                        type: 'post',//提交的方式
                        dataType:'json',
                        contentType:"application/json; charset=utf-8",
                        data:JSON.stringify(dataUpdate),
                        success: function(data) {
                            if (data.httpCode==200) {
                            	top.layer.close(close);
                                top.layer.alert("更新成功");
                                top.layer.close(index);
                            } else{
                            	top.layer.close(close);
                                alert(data.msg);
                            }
                        }
                    });

                },
                btn2:function(index,layarDom){//关闭
                    ko.cleanNode(layarDom.get(0));
                },
                success:function(layarDom,index){//弹层加载成功
                    ko.applyBindings(newModel, layarDom.get(0));
                    //var unmapped = ko.mapping.toJS(operate.entityModel);
                }
            });
        },
        //审核专家或经纪人
        auditUser:function(id){
        	var row = getTable().bootstrapTable("getRowByUniqueId",id);
        	 if(row.userType==2){//审核经纪人
        	 	auditSys_org(row);
        	 }else{
        	 	auditExpert(row);
        	 }
        }
        ,
        //搜索清空绑定
        operateSearch:function(){
            //ko模型绑定
            ko.applyBindings(koModel.searchModel, $("#toolbar").get(0));
            $("#btn_search").click(function(event) {
                var searchObj = ko.mapping.toJS(koModel.searchModel);
                //alert(JSON.stringify(searchObj));
                $("#tb_dept").bootstrapTable("refreshOptions",{pageNumber:1});
                refreshTable();
            });
            $("#btn_reset").click(function(event) {
                $("#startTime").val("");
                $("#endTime").val("");
                koModel.searchModel.mobile("");
                koModel.searchModel.name("");
                koModel.searchModel.numId("");
                koModel.searchModel.userType("");
                koModel.searchModel.checkFlag("");
            });
        },
        //app用户数据校验
        operateCheck:function(entity){
        	var pass = "^[A-Za-z0-9]{1,}$";
        	var regexp = "^[0-9]+(.[0-9]{1,2})?$";
        	var reg = "(^[0-9]{15}$)|(^[0-9]{18}$)|(^[0-9]{17}([0-9]|X|x)$)";
        	var emailRe = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$";
            if (entity.name=="") {
                alert("姓名不能为空，请填写姓名!");
                return false;
            }
            if (entity.status=="") {
                alert("状态不能为空，请选择状态!");
                return false;
            }
            if (entity.memPassword=="") {
                alert("密码不能为空，请输入密码!");
                return false;
            }
            if(!entity.memPassword.match(pass)){
        		alert("密码只能是数字和字母!");
            	return false;
        	}
            if (entity.checkFlag=="") {
                alert("审核状态不能为空，请选择审核状态!");
                return false;
            }
            if (entity.userType=="") {
                alert("用户类型不能为空，请选择用户类型!");
                return false;
            }
            if (entity.provinceId=="") {
                alert("省份不能为空，请选择用户省份!");
                return false;
            }
            if (!entity.mobile.match(regexp)) {
                alert("手机号只能为数字!");
                return false;
            }
            if(entity.email){
            	if (!entity.email.match(emailRe)) {
	                alert("邮箱不合法!");
	                return false;
	            }
            }
            if (entity.mobile.length!=11) {
                alert("手机号为11位!");
                return false;
            }
            if (!entity.idCardNo.match(reg)) {
                alert("身份证格式有误!");
                return false;
            }
            return true;
        },
        
        //诊所数据校验
	    operateClinicCheck:function(entity){
	        if (entity.clinicsName=="") {
	            alert("诊所名称不能为空，请输入诊所名称!");
	            return false;
	        }
	        if (entity.status=="") {
	            alert("诊所状态不能为空，请选择!");
	            return false;
	        }
	        return true;
	    },
	    
	    //专家附属数据校验
        operateExpertCheck:function(entity){
        	var regexp = "^[0-9]+(.[0-9]{1,2})?$";
            if (entity.status=="") {
                alert("状态不能为空，请选择!");
                return false;
            }
            if (entity.level=="") {
                alert("讲师等级不能为空，请选择!");
                return false;
            }
            if (!entity.orderValue.match(regexp)) {
                alert("排序值只能为数字!");
                return false;
            }
            if (!entity.levelaPrice.match(regexp)) {
                alert("等级价格只能为数字!");
                return false;
            }
            if (!entity.workingYears.match(regexp)) {
                alert("工龄只能为数字!");
                return false;
            }
            if(entity.rate>=1||entity.rate<=0.01){
            	alert("提成比例应该在0.01到1之间!");
            	return false;
            }
            return true;
        }
        
    }
    
    //审核经纪人
    function auditSys_org(row){
    	var newModel = ko.mapping.fromJS(row);
    	switch (row.step){
    		case "1":
    		case "2":
    				newModel.step("注册成功");
    				break;
    		case "3":
    				newModel.step("完成支付");
    				break;
    		default:
    				newModel.step("完善资料");
    				break;
    	}
    	var content = $get("./agentAudit.html");
    	
		top.layer.open({
            title:"信息审核",
            type: 1,
            area: "500px",
            maxHeight:maxHeight,
            content:content,
            btn: ["跳过支付","审核通过", "拒绝通过","取消"],
            yes: function(index, layerDom){
            	if(row.step==3){
            		top.layer.alert('已经支付过',{icon: 6});
            		return;
            	}
            	var member = {step:3,id:row.id};
                $$ajax({
		            url: __addOrUpdateUrl,
		            type: 'post',//提交的方式
		            dataType:'json',
		            contentType:"application/json; charset=utf-8",
		            data:JSON.stringify(member),
		            success: function(data) {
		                console.log(data.msg)
		                if (data.httpCode==200) {
		                	top.layer.alert('已跳过支付',{icon: 6});
		                	refreshTable();
		                } else{
		                    alert(data.msg);
		                    location.reload();
		                }
		            }
		        });
            },
            btn2: function(index, layerDom){
            	if(row.checkFlag==1){
            		alert("已经审核通过");
            		top.layer.close(index);
            		return;
            	}
            	var member = {checkFlag:1,id:row.id};
                changeStatus(member);
                top.layer.close(index);
            },
            btn3:function(index,layarDom){//拒绝通过
            	if(row.checkFlag==-1){
            		top.layer.close(index);
            		return;
            	}
            	var member = {checkFlag:-1,id:row.id};
                changeStatus(member);
                top.layer.close(index);
                //ko.cleanNode(layarDom.get(0));
            },
            btn4:function(index,layarDom){//关闭
                //ko.cleanNode(layarDom.get(0));
                top.layer.close(index);
                return;
                   
            },
            success:function(layarDom,index){//弹层加载成功
               ko.applyBindings(newModel, layarDom.get(0));
            }
		});    	
    }
    
    //审核专家
    function auditExpert(row){
    	row.orgName = "";
    	row.titles = "";
    	row.goodat = "";
    	row.dept = "";
    	var newModel = ko.mapping.fromJS(row);
    	var content = $get("./expertAudit.html");
		top.layer.open({
            title:"信息审核",
            type: 1,
            area: "500px",
            content:content,
            maxHeight:maxHeight,
            btn: ["审核通过", "拒绝通过","取消"],
            yes: function(index, layerDom){
            	if(row.checkFlag==1){
            		alert("已经审核通过");
            		top.layer.close(index);
            		return;
            	}
            	var member = {checkFlag:1,id:row.id};
                changeStatus(member);
                top.layer.close(index);
            },
            btn2:function(index,layarDom){//拒绝通过
            	if(row.checkFlag==-1){
            		top.layer.close(index);
            		return;
            	}
            	var member = {checkFlag:-1,id:row.id};
                changeStatus(member);
                top.layer.close(index);
                //ko.cleanNode(layarDom.get(0));
            },
            btn3:function(index,layarDom){//关闭
                //ko.cleanNode(layarDom.get(0));
                top.layer.close(index);
                return;
                   
            },
            success:function(layarDom,index){//弹层加载成功
            	var data={id:row.id};
            	$$ajax({
                    url: __getExpertByIdUrl,
                    type: 'post',//提交的方式
                    dataType:'json',
                    data:data,
                    success: function(response) {
                        console.log(response.msg)
                        if (response.httpCode==200) {
                        	var expert = response.data;
                        	if(expert){
                        		newModel.titles(expert.titles);
	                        	newModel.goodat(expert.goodat);
	                        	newModel.dept(expert.dept);
	                        	newModel.orgName(expert.orgName);
                        	}
                        	ko.applyBindings(newModel, layarDom.get(0));
                        } else{
                            alert(response.msg);
                            //location.reload();
                        }
                    }
                });
               // ko.applyBindings(newModel, layarDom.get(0));
                //var unmapped = ko.mapping.toJS(operate.entityModel);
            }
		});    	
    }
	
	
    var dateInit = {
        Init: function () {
            var that = this;
            laydate.render(this.customInitLayDate($("#startTime").get(0)));
            laydate.render(this.customInitLayDate($("#endTime").get(0)));
        },
        customInitLayDate: function (elem) {
        	//elem 传入的 原生dom 对象
            return {
                elem: elem,//
                format: 'yyyy-MM-dd HH:mm:ss',
                min: '1971-01-01 00:00:00', //设定最小日期为当前日期
                max: '2099-06-16 23:59:59', //最大日期
                istime: true,
                istoday: false,
                done:function  (value, date, endDate) {
               		$(elem).change();
                }
            }
        }
    }
	//审核状态改变
	function changeStatus(member){
		$$ajax({
            url: __addOrUpdateUrl,
            type: 'post',//提交的方式
            dataType:'json',
            contentType:"application/json; charset=utf-8",
            data:JSON.stringify(member),
            success: function(data) {
                console.log(data.msg)
                if (data.httpCode==200) {
                    refreshTable();
                } else{
                    alert(data.msg);
                    location.reload();
                }
            }
        });
	}
	
	//上传图片进行预览
	function preview(str,layarDom){
		$("#"+str+"FileInput",$(layarDom)).change(function(){
    		var file = this.files[0];
		   	if (window.FileReader) {    
	            var reader = new FileReader();    
	            reader.readAsDataURL(file);    
	            //监听文件读取结束后事件    
	          	reader.onloadend = function (e) {
	            	$("#"+str+"Suolue",$(layarDom)).attr("src",e.target.result);    //e.target.result就是最后的路径地址
	            };    
		    } 
    	});
	}
	
	//图片上传
	function upload(str,attribute,layerDom,url){
		var formData = new FormData();
        formData.append(str, $("#"+str+"FileInput", $(layerDom)).get(0).files[0]);
        $.ajax({
            url: url,
            type: "POST",
            data: formData,
            async:false,
            /**
            *必须false才会自动加上正确的Content-Type
            */
            contentType: false,
            /**
            * 必须false才会避开jQuery对 formdata 的默认处理
            * XMLHttpRequest会对 formdata 进行正确的处理
            */
            processData: false,
            success: function (data) {
            	if (data.httpCode == "200") {
                	attribute(data.urls[0]);
                    //alert("上传成功！");
                }else{
                	//console.log(data.msg);
                }
            },
            error: function () {
                alert("上传失败！！请检查本地网络!");
            }
        });
	}
	
</script>

</html>